package com.cmc.cloud.cmclink.doc.controller.admin.multimodaltransport;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.rpcservice.VoyScheduleService;
import com.cmc.cloud.cmclink.doc.service.multimodaltransport.MultiBlnoOpService;
import com.cmc.cloud.cmclink.doc.vo.blnovo.BlnoPageRespVO;
import com.cmc.cloud.cmclink.doc.vo.multimodaltransport.multiblnoop.MultiBlnoOpReqVO;
import com.cmc.cloud.cmclink.doc.vo.multimodaltransport.multiblnoop.MultiBlnoUpdateVO;
import com.cmc.cloud.cmclink.doc.vo.multimodaltransport.multiblnoop.MultiBlnoVelVoyVO;
import com.cmc.cloud.cmclink.doc.vo.multimodaltransport.multiblnoop.MultiBlnoVslVelReqVO;
import com.cmc.cloud.cmclink.doc.vo.sovo.sovslvoyvo.SoVslvoyScheduleVO;
import com.cmc.cloud.cmclink.svl.api.base.req.BargePolPodReqDTO;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import com.cmes.platform.system.api.permission.PermissionApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author lzp
 * @date 2025/10/23 14:41
 * @description
 */
@Tag(name = "管理后台 - 出口单证操作")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/multi/blno")
public class MultiBlnoOpController {

    @Autowired
    private MultiBlnoOpService multiBlnoOpService;

    @Autowired
    private VoyScheduleService voyScheduleService;

    @Operation(summary = "获得提单主信息分页")
    @PostMapping("/page")
    @PreAuthorize("@ss.hasPermission('doc:billLoadingOperation:search')")
    public CommonResult<PageResult<BlnoPageRespVO>> getMultiBlnoPage(@Valid @RequestBody MultiBlnoOpReqVO multiBlnoOpReqVo) {
        PageResult<BlnoPageRespVO> blnoPage = multiBlnoOpService.getMultiBlnoPage(multiBlnoOpReqVo);
        return CommonResult.success(blnoPage);
    }

    @Operation(summary = "更新驳船船名航次")
    @PostMapping("/upvslvoy")
    @PreAuthorize("@ss.hasPermission('doc:billLoadingOperation:setBargeVessel')")
    public CommonResult updateBlnoVslVoyInfo(@Valid @RequestBody MultiBlnoUpdateVO multiBlnoUpdateVo) {
        multiBlnoOpService.updateBlnoVslVoyInfo(multiBlnoUpdateVo);
        return CommonResult.success();
    }

    @Operation(summary = "查询驳船信息")
    @PostMapping("/sevslvoy")
    @PreAuthorize("@ss.hasPermission('doc:billLoadingOperation:search')")
    public CommonResult<List<MultiBlnoVelVoyVO>> getMultiBlnoVslVoyInfo(@Valid @RequestBody List<Long> blnoIds) {
        return CommonResult.success(multiBlnoOpService.getMultiBlnoVslVoyInfo(blnoIds));
    }

    @Operation(summary = "驳船船期")
    @PostMapping("/line/vslvoy")
    @PreAuthorize("@ss.hasPermission('doc:billLoadingOperation:search')")
    public CommonResult<List<SoVslvoyScheduleVO>> multiLineScheduleByPolPod(@Valid @RequestBody MultiBlnoVslVelReqVO multiBlnoVslVelReqVo) {
        BargePolPodReqDTO bargePolPodReqDto = BeanUtil.copyProperties(multiBlnoVslVelReqVo, BargePolPodReqDTO.class);
        return CommonResult.success(voyScheduleService.multiLineScheduleByPolPod(bargePolPodReqDto));
    }
}
